import React, { Component } from 'react'
import { Redirect, Switch, Route } from 'react-router-dom'
import store from 'store'
import { Layout } from 'antd'

import Header from '../../components/Header'
import LeftNav from '../../components/LeftNav'
import Footer from '../../components/Footer'
import Home from '../Home'
import Commodity from '../Commodity'
import UserMgt from '../UserMgt'
import RolesMgt from '../RolesMgt'
import Charts from '../Charts'

const { Sider, Content } = Layout

export default class Admin extends Component {
  render() {
    const { id } = store.get('user') || {}
    if (id) {
      return (
        <Layout style={{ minHeight: '100vh' }}>
          <Sider>
            <LeftNav />
          </Sider>
          <Layout>
            <Header>Header</Header>
            <Content
              style={{
                backgroundColor: '#fff',
                padding: '16px'
              }}
            >
              <Switch>
                <Route path="/home" component={Home} />
                <Route path="/commodity" component={Commodity} />
                <Route path="/userMgt" component={UserMgt} />
                <Route path="/rolesMgt" component={RolesMgt} />
                <Route path="/charts" component={Charts} />
                <Redirect to="/home" />
              </Switch>
            </Content>
            <Footer />
          </Layout>
        </Layout>
      )
    } else {
      return <Redirect to="/login" />
    }
  }
}
